package com.gulimall.cart.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

@Data
public class Cart {

    /**
     * 商品详情
     */
    private List<CartItem> items;

    /**
     * 商品数量
     */
    private Integer productCount;

    /**
     * 类型数量
     */
    private Integer typeCount;

    /**
     * 总金额
     */
    private BigDecimal totalPrice;

    /**
     * 满减
     */
    private BigDecimal reduce = new BigDecimal(0);

    public Integer getTypeCount() {
        return items == null ? 0 : items.size();
    }

    public Integer getProductCount() {
        int count = 0;
        if (items != null && items.size() > 0) {
            for (CartItem item : items) {
                count += item.getCount();
            }
        }
        return count;
    }

    public BigDecimal getTotalPrice() {
        BigDecimal price = new BigDecimal(0);
        if (items != null && items.size() > 0) {
            for (CartItem item : items) {
                price = price.add(item.getTotalPrice());
            }
        }
        return price.subtract(reduce);
    }

}
